package com.wc.算法基础课.E第五讲动态规划.线性DP.最短编辑距离;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/4/9 17:26
 * @description
 * https://www.acwing.com/problem/content/904/
 */
public class Main {
    /**
     * 思路：
     * @see com.wc.算法基础课.E第五讲动态规划.线性DP.编辑距离.Main;
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010;
    static int[][] f = new int[N][N];
    static char[] s, t;
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        s = (" " + sc.next()).toCharArray();
        m = sc.nextInt();
        t = (" " + sc.next()).toCharArray();
        for (int i = 1; i <= m; i++) f[0][i] = i;
        for (int i = 1; i <= n; i++) f[i][0] = i;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                f[i][j] = Math.min(f[i - 1][j] + 1, f[i][j - 1] + 1);
                if (s[i] == t[j]) f[i][j] = Math.min(f[i][j], f[i - 1][j - 1]);
                else f[i][j] = Math.min(f[i][j], f[i - 1][j - 1] + 1);
            }
        }
        out.println(f[n][m]);
        out.flush();
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            String s = nextLine();
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    boolean hasNext() {
        while (st == null || !st.hasMoreElements()) {
            String s = nextLine();
            if (s == null) return false;
            st = new StringTokenizer(s);
        }

        return true;
    }

}

